/******************************************************************************
 *
 * @file       chatdialog.h
 * @brief      主界面
 *
 * @author     ario
 * @date       2024/08/08
 * @history
 *****************************************************************************/

#ifndef CHATDIALOG_H
#define CHATDIALOG_H

#include <QDialog>
#include <QListWidgetItem>
#include "global.h"
#include "userdata.h"

namespace Ui {
class ChatDialog;
}

class StateWidget;
class ChatDialog : public QDialog
{
    Q_OBJECT

public:
    explicit ChatDialog(QWidget *parent = nullptr);
    ~ChatDialog();

protected:
    bool eventFilter(QObject *, QEvent *) override;

private:
    void addChatUserList();
    void AddLBGroup(StateWidget* lb);
    void ClearLabelState(StateWidget* lb);
    void handleGlobalMousePress(QMouseEvent *mouseEvent);
    void SetSelectChatItem(int uid = 0);
    void SetSelectChatPage(int uid = 0);
    void LoadMoreChatUser();
    void LoadMoreConUser();
    void UpdateChatMsg(std::vector<std::shared_ptr<TextChatData>> msgdata);

public slots:
    void ShowSearch(bool bsearch);
    void slot_apply_friend(std::shared_ptr<AddFriendApply> apply);

private slots:
    void slot_loading_chat_user();
    void slot_loading_contact_user();
    void slot_side_chat();
    void slot_side_contact();
    void slot_text_changed(const QString & str);
    void slot_add_auth_friend(std::shared_ptr<AuthInfo> auth_info); // 添加新朋友到聊天列表
    void slot_auth_rsp(std::shared_ptr<AuthRsp> auth_rsp); // 添加新朋友到聊天列表
    void slot_jump_chat_item(std::shared_ptr<SearchInfo> si);
    void slot_friend_info_page(std::shared_ptr<UserInfo> user_info);
    void slot_switch_apply_friend_page();
    void slot_jump_chat_item_from_infopage(std::shared_ptr<UserInfo> user_info);
    void slot_item_clicked(QListWidgetItem * item);
    void slot_append_send_chat_msg(std::shared_ptr<TextChatData> msgdata);
    void slot_text_chat_msg(std::shared_ptr<TextChatMsg>);


private:
    Ui::ChatDialog *ui;
    ChatUIMode _mode;
    ChatUIMode _state;
    bool _b_loading;
    QList<StateWidget *> _lb_list;
    QMap<int, QListWidgetItem*> _chat_items_added;
    int _cur_chat_uid;
    QWidget* _last_widget;
};

#endif // CHATDIALOG_H
